# -*- coding:utf-8 -*-
# @FileName : app\api\v1\__init__.py
# @Time     : 2025/11/28
# @Author   : 天空之城
"""API v1版本蓝图模块

此模块定义v1版本API的蓝图，并注册相关路由和错误处理。
"""
from flask import Blueprint
from app.api.v1.users.routes import users_bp
from app.api.v1.conversations.routes import conversations_bp
from app.api.v1.models.routes import models_bp
from app.api.v1.auth.routes import auth_bp
from app.api.v1.history.routes import history_bp
from app.api.v1.chat.routes import chat_bp

# 创建v1版本API蓝图
api_bp = Blueprint('api_v1', __name__)

# 注册用户相关路由
api_bp.register_blueprint(users_bp, url_prefix='/users')

# 注册认证相关路由
api_bp.register_blueprint(auth_bp, url_prefix='/auth')

# 注册对话相关路由
api_bp.register_blueprint(conversations_bp, url_prefix='/conversations')

# 注册模型相关路由
api_bp.register_blueprint(models_bp, url_prefix='/models')

# 注册历史记录相关路由
api_bp.register_blueprint(history_bp, url_prefix='/history')

# 注册聊天相关路由
api_bp.register_blueprint(chat_bp, url_prefix='/chat')

# 可以在这里添加v1版本的错误处理
@api_bp.errorhandler(404)
def handle_404(error):
    """处理404错误"""
    return {'error': 'Not found'}, 404

@api_bp.errorhandler(500)
def handle_500(error):
    """处理500错误"""
    return {'error': 'Internal server error'}, 500
